<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <div id="gd-map"></div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      poss: {},
      msg: 'Welcome to Your Vue.js App',
      test: {},
    };
  },
  mounted() {
    navigator.geolocation.getCurrentPosition(
      (pos) => {
        this.msg = pos;
      },
      (err) => {
        this.msg = err;
      },
      {
        timeout: 3000,
      }
    );
    /* let that = this;
    // getCurrentPosition(成功时的回调函数，错误时的回调函数，可选的配置对象);
    navigator.geolocation.getCurrentPosition(
      (pos) => {
        this.msg = pos;
        console.log('获取位置信息成功：', pos.coords);
        that.poss = {
          longitude: pos.coords.longitude,
          latitude: pos.coords.latitude,
        };
        let map = new AMap.Map('gd-map', {
          zoom: 15,
        });
        // let marker = new AMap.Marker({
        //   position: new AMap.LngLat(
        //     pos.coords.longitude,
        //     pos.coords.latitude
        //   ), // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
        //   title: '当前位置',
        // });
        // map.add(marker);
        AMap.plugin('AMap.Geocoder', function () {
          var geocoder = new AMap.Geocoder({
            // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
            city: '',
          });
          var lnglat = [91.7, 29.39];
          geocoder.getAddress(lnglat, function (status, result) {
            if (status === 'complete' && result.info === 'OK') {
              // result为对应的地理位置详细信息
            }
            console.log('逆，', result);
          });
        });
      },
      (err) => {
        console.log('位置信息失败：', err);
        this.msg = err;
      }
    ); */
  },
  methods: {},
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#gd-map {
  width: 100%;
  height: 300px;
}
</style>
